using System;
using System.CodeDom;
using System.Linq;
using System.Collections;
using System.Collections.Generic;

namespace CodeDom
{
  internal static class FieldPropertyGeneratorFactory {
    /// <exception cref="InvalidOperationException"><c>InvalidOperationException</c>.</exception>
    static public TemplateFieldGenerator Create(TemplateField field)
    {
      if (field.Type == null)
        throw new InvalidOperationException(string.Format("No field type set for field {0}", field.Name));
      switch (field.Type.ToLower())
      {
        case "droplink":
        case "droptree":
        case "grouped droplink":
          return new ReferenceFieldPropertyGenerator(field);
        case "general link":
          //TODO: Replace with actual field property generator
          return new FieldWrapperPropertyGenerator(field, "Sitecore.Data.Fields.LinkField");
        case "checkbox":
          return new CheckboxFieldPropertyGenerator(field);
        case "file":
          //TODO: Replace with actual field property generator
          return new FieldWrapperPropertyGenerator(field, "Sitecore.Data.Fields.FileField");
        case "image":
          //TODO: Replace with actual field property generator
          return new FieldWrapperPropertyGenerator(field, "Sitecore.Data.Fields.ImageField");
        case "datetime":
        case "date":
          return new DateTimeFieldPropertyGenerator(field);
        case "checklist":
        case "droplist":
        case "grouped droplist":
        case "multilist":
        case "treelist":
        case "treelistex":
          return new ListFieldPropertyGenerator(field);
        default:
          return new DefaultFieldPropertyGenerator(field);
      }
    }
  }
}